﻿/***************************************************
Copyright (C) 2012 Alexander Forselius

Permission is hereby granted, free of charge, to any person obtaining a copy of this 
software and associated documentation files (the "Software"), to deal in the Software
 without restriction, including without limitation the rights to use, copy, modify, merge,
 publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons 
 to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Bungalow
{
    /// <summary>
    /// MenuItem for SPMenu
    /// </summary>
    [Serializable]
    public class SPListItem
    {
        public bool Touched { get; set; }
        public Color Color
        {
            get
            {
                return this.color;
            }
            set
            {
                this.color = value;
                CustomColor = true;
            }
        }
        private Color color;

        public bool CustomColor { get; set; }
        public Uri Uri { get; set; }
        public String Text { get; set; }
        public Image Icon;
        private SPListView parent;
        public SPListItem AddItem(String text, Uri uri)
        {
            SPListItem c = new SPListItem(this.Parent);
            c.Text = text;
            c.Uri = uri;
            this.Children.Add(c);
            return c;
        }
        public SPListItem AddItem(String text, Uri uri, Image icon)
        {
            SPListItem c = new SPListItem(this.Parent);
            c.Text = text;
            c.Uri = uri;
            c.Icon = icon;
            this.Children.Add(c);
            return c;
        }
        public SPListView Parent
        {
            get
            {
                return this.parent;
            }
        }
        public Boolean Selected
        {
            get;
            set;
        }
        public SPListItem GetItemByUri(Uri uri)
        {

            foreach (SPListItem item in this.Children)
            {
                if (item.Uri.ToString().Contains(uri.ToString()))
                {
                    return item;
                }
                else
                {
                    return item.GetItemByUri(uri);
                }
            }
            return null;

        }
        public bool HasUri( Uri uri, ref bool positive)
        {
            foreach (SPListItem item in this.Children)
            {
                if (item.Uri.ToString().Contains(uri.ToString()))
                {
                    positive = true;
                }
                else
                {
                    item.HasUri(uri, ref positive);
                }
            }
            return positive;

        }
        public List<SPListItem> Children { get; set; }
        public SPListItem(SPListView parent)
        {
            this.parent = parent;
            this.Children = new List<SPListItem>();
        }
        public SPListItem()
        {
        }
        public bool Expanded { get; set; }
    }
}
